<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-08-30 19:42
 *
 * Version: 2.0
 */

namespace App\Modules\Employee\Transformers;


use App\Lib\Utilities;
use League\Fractal\TransformerAbstract;

class GetBarberListCommentTransformer extends TransformerAbstract
{
	private $list;
	public function __construct($list)
	{
		$this->list = $list;
	}

	public function transformer(){
		$list = $this->list->items();
		$commentList = [];
		if(isset($list)){
			foreach ($list as &$v){
				$resource = $v->resource;
				$newList = null;
				if(isset($resource)){
					foreach ($resource as $k){
						if($k->type == 1 && isset($k->url->image)){
							$newList['image'][]  = $k->url->image;
						}else if($k->type == 2 && isset($k->url->url)){
							$newList['video'] = [
								'url' => $k->url->url,
								'thumb' => $k->url->thumb
							];
						}
					}
				}
				$vs= $v->toArray();
				$vs['resource'] = $newList;
				$vs['likeStatus'] = empty($vs['order_comment_like']) ? 0 : 1;
				unset($vs['order_comment_like']);
				$commentList[] = $vs;
			}
			unset($v);
		}
		$totalList = Utilities::dealPage($this->list);
		$totalList['items'] = $commentList;
		return $totalList;
	}
}